package com.starhub.application.collection.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.starhub.application.collection.entity.KnowledgeBase;
import com.starhub.application.collection.mapper.KnowledgeBaseMapper;
import com.starhub.application.collection.service.KnowledgeBaseService;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 知识库服务实现类
 * @version: V1.0
 * @author: luosw
 * @time 2025-06-20
 */
@Service
public class KnowledgeBaseServiceImpl implements KnowledgeBaseService {

    private final KnowledgeBaseMapper knowledgeBaseMapper;

    public KnowledgeBaseServiceImpl(KnowledgeBaseMapper knowledgeBaseMapper) {
        this.knowledgeBaseMapper = knowledgeBaseMapper;
    }

    @Override
    public int insert(KnowledgeBase knowledgeBase) {
        return knowledgeBaseMapper.insert(knowledgeBase);
    }

    @Override
    public int updateById(KnowledgeBase knowledgeBase) {
        return knowledgeBaseMapper.updateById(knowledgeBase);
    }

    @Override
    public KnowledgeBase selectById(Long id) {
        return knowledgeBaseMapper.selectById(id);
    }

    @Override
    public KnowledgeBase selectByIdAndNotDeleted(Long id) {
        LambdaQueryWrapper<KnowledgeBase> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(KnowledgeBase::getId, id)
                .eq(KnowledgeBase::getDeleteType, 0);
        return knowledgeBaseMapper.selectOne(queryWrapper);
    }

    @Override
    public int deleteById(Long id) {
        KnowledgeBase knowledgeBase = new KnowledgeBase();
        knowledgeBase.setDeleteType(1);
        knowledgeBase.setId(id);
        return knowledgeBaseMapper.updateById(knowledgeBase);
    }


    @Override
    public int deleteRecord(Long id) {
        return knowledgeBaseMapper.deleteById(id);
    }

    @Override
    public List<KnowledgeBase> selectByMap(Map<String, Object> params) {

        Map<String, Object> columnMap = new HashMap<>();
        columnMap.put("delete_type",0);
        return knowledgeBaseMapper.selectByMap(columnMap);
    }


    @Override
    public List<KnowledgeBase> getActiveKnowledgeBase(Map<String, Object> params) {
        Map<String, Object> columnMap = new HashMap<>();
        columnMap.put("delete_type",0);
        columnMap.put("status","enabled");
        return knowledgeBaseMapper.selectByMap(columnMap);
    }
} 